﻿using System;

namespace Core
{
    public static class Config
    {
        public const int BUFF_SIZE = 1024 * 1024;

        // | (4B int)消息长度 | (1B byte)标志位 | (4B uint)SID | (2B ushort)MID | MESSAGE |
        // 标志位左到右：1位-是否转发，1位-是否是响应RPC消息，剩余位-RpcID

        public const int MESSAGE_LENGTH_SIZE = 4;
        public const int RPC_ID_SIZE = 1;
        public const int SESSION_ID_SIZE = 4;
        public const int MESSAGE_ID_SIZE = 2;

        public const int MESSAGE_LENGTH_POSITION = 0;
        public const int RPC_ID_POSITION = MESSAGE_LENGTH_POSITION + MESSAGE_LENGTH_SIZE;
        public const int SESSION_ID_POSITION = RPC_ID_POSITION + RPC_ID_SIZE;
        public const int MESSAGE_ID_POSITION = SESSION_ID_POSITION + SESSION_ID_SIZE;
        public const int MESSAGE_BODY_POSITION = MESSAGE_ID_POSITION + MESSAGE_ID_SIZE;

        public const byte RPC_TRANSPOND_MASK = 1 << 7;
        public const byte RPC_RESPONSE_MASK = 1 << 6;
        public const byte RPC_ID_MASK = (RPC_TRANSPOND_MASK | RPC_RESPONSE_MASK) ^ Byte.MaxValue;

        public const int MAX_MESSAGE_SIZE = BUFF_SIZE / 2;
        public const int MAX_CONNECT_COUNT = 5000;
    }
}
